package com.example.zk1

import android.content.Context
import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.ImageView
import com.bumptech.glide.Glide
import com.example.common.mvvm.BaseActivity
import com.example.zk1.databinding.ActivityMainBinding
import com.example.zk1.login.LoginActivity
import com.youth.banner.loader.ImageLoader

class MainActivity : BaseActivity<ActivityMainBinding,MainViewModel>() {
    val list = mutableListOf<String>()//轮播图的网址
    override fun getLayout(): Int  = R.layout.activity_main

    override fun getViewModel(): Class<MainViewModel>  = MainViewModel::class.java

    override fun initView() {
        viewmodel.getBanner()
        binding.tvTg.setOnClickListener {
            startActivity(Intent(this,LoginActivity::class.java))
        }
    }

    override fun initData() {
        viewmodel.success.observe(this){
            if(it.code==200){
                it.data.forEach {
                    list.add(it.imagePath)
                }
                binding.banner.setImages(list)
                binding.banner.setImageLoader(object: ImageLoader(){
                    override fun displayImage(
                        context: Context?,
                        path: Any?,
                        imageView: ImageView?
                    ) {
                        if(context!=null&&imageView!=null){
                            Glide.with(context).load(path.toString()).into(imageView)
                        }

                    }
                })
                binding.banner.start()

            }

        }
    }

}